package com.vegetable.modules.service.baseData.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.vegetable.common.utils.PageUtils;
import com.vegetable.common.utils.Query;
import com.vegetable.modules.entity.baseData.VehicleManagement;
import com.vegetable.modules.mapper.baseData.VehicleManagementMapper;
import com.vegetable.modules.service.baseData.IVehicleManagementService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * <p>
 * 车辆管理 服务实现类
 * </p>
 *
 * @author wangruijie
 * @since 2024-03-04
 */
@Slf4j
@Service
@AllArgsConstructor
public class VehicleManagementServiceImpl extends ServiceImpl<VehicleManagementMapper, VehicleManagement> implements IVehicleManagementService {

    /**
     * 车辆管理
     * @param params
     * @return
     */
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String driverName = (String)params.get("driverName");
        String phoneNumber = (String)params.get("phoneNumber");
        String licensePlate = (String)params.get("licensePlate");
        String isDel = (String)params.get("isDel");
        Integer isDel_int = 0;
        if (StringUtils.isNotBlank(isDel)){
            isDel_int = Integer.valueOf(isDel);
        }
        IPage<VehicleManagement> page = this.page(
                new Query<VehicleManagement>().getPage(params),
                new QueryWrapper<VehicleManagement>()
                        .like(StringUtils.isNotBlank(driverName),"driver_name", driverName)
                        .like(StringUtils.isNotBlank(phoneNumber),"phone_number", phoneNumber)
                        .like(StringUtils.isNotBlank(licensePlate),"license_plate", licensePlate)
                        .eq(ObjectUtils.isNotEmpty(isDel_int),"is_del", isDel_int)
                        .orderByDesc("create_time")
        );

        return new PageUtils(page);
    }
}
